Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to lock mouse cursor on rotate/grab pan #13

Merged
merged 1 commit into from
May 11, 2024

Conversation

juliohq
Copy link
Contributor

@juliohq juliohq commented Apr 28, 2024

This PR introduces two new variables: lock_on_rotate and lock_on_drag. They are meant to allow the mouse cursor to stay in place while rotating/dragging. The cursor is hidden when performing such actions (so CursorGrabMode::Locked works fine on Windows and Linux).

I've set the default to false for both lock_on_rotate and lock_on_drag variables and true. Do you think they should be enabled by default?

Copy link
Owner

@Plonq Plonq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the PR! Bevy has built-in cursor lock, so we should use that instead of manually storing and setting the cursor position. See https://bevy-cheatbook.github.io/window/mouse-grab.html

Do you think they should be enabled by default?

I think they should remain false by default.

src/controller.rs Outdated Show resolved Hide resolved
@Plonq
Copy link
Owner

Plonq commented Apr 29, 2024

This actually doesn't work. Perhaps your cursor locking is messing with MouseMotion events.

Screen.Recording.2024-04-29.at.19.55.06.mov

@juliohq juliohq force-pushed the lock-on-rotate-and-grab-pan branch from b2b39b6 to 4dd3bf7 Compare April 29, 2024 10:00
@juliohq
Copy link
Contributor Author

juliohq commented Apr 29, 2024

This actually doesn't work. Perhaps your cursor locking is messing with MouseMotion events.

Screen.Recording.2024-04-29.at.19.55.06.mov

That's the intended behavior, the mouse cursor stays in place.

@juliohq juliohq force-pushed the lock-on-rotate-and-grab-pan branch from 4dd3bf7 to 01cf4f8 Compare April 29, 2024 10:07
@juliohq juliohq requested a review from Plonq April 29, 2024 12:41
@Plonq
Copy link
Owner

Plonq commented Apr 30, 2024

This actually doesn't work. Perhaps your cursor locking is messing with MouseMotion events.

Screen.Recording.2024-04-29.at.19.55.06.mov

That's the intended behavior, the mouse cursor stays in place.

If you watch the video, you can see the camera actually barely moves, but I'm trying to move it. It's stuck, can't rotate it and can't drag it.

Maybe this is OS dependent.

@Plonq
Copy link
Owner

Plonq commented May 1, 2024

Note: what I suspect is happening is that manually moving the cursor back to where it started actually triggers MouseMotion events, thus also moving the camera back to where it started. If that's the case, you'll have to find an alternative solution.

@juliohq juliohq force-pushed the lock-on-rotate-and-grab-pan branch from 01cf4f8 to f4fb1b9 Compare May 5, 2024 19:34
@juliohq
Copy link
Contributor Author

juliohq commented May 5, 2024

I think we can use bevy's built-in CursorGrabMode::Locked mode until rust-windowing/winit#3094 is solved. As pointed here, the issue is invisible if you just hide the cursor on Windows and Linux, so as long as the locked mode works fine on macOS I think we're fine.

@Plonq
Copy link
Owner

Plonq commented May 6, 2024

I think we can use bevy's built-in CursorGrabMode::Locked mode until rust-windowing/winit#3094 is solved. As pointed here, the issue is invisible if you just hide the cursor on Windows and Linux, so as long as the locked mode works fine on macOS I think we're fine.

Sounds good to me

@juliohq
Copy link
Contributor Author

juliohq commented May 11, 2024

@Plonq is there anything missing for this PR to be merged?

@Plonq
Copy link
Owner

Plonq commented May 11, 2024

Apologies! I didn't realise you'd already made that change.

@Plonq Plonq merged commit 2e9be44 into Plonq:main May 11, 2024
5 checks passed
@juliohq juliohq deleted the lock-on-rotate-and-grab-pan branch May 12, 2024 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants